package GUILayer;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JTextField;

import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.UIManager;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JTextField;

import CtrLayer.SchemeCtr;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;


public class BradenScale extends JFrame {

	private JPanel contentPane;
	private JTextField nameField;
	private SchemeCtr schemeCtr;
	private JComboBox nutritionBox;

	

	/**
	 * Create the frame.
	 * @param info 
	 * @param model 
	 */
	public BradenScale(final JLabel mainFrameLabel, final DefaultTableModel model) {
		setTitle("Create Braden Scale");
		
		setBounds(100, 100, 635, 511);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
    	try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
            setIconImage(Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("b4/advancedgui/menu/resources/green_arrow_right.png")));
        } catch (Exception ex) {
            Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
           
        }
		
		schemeCtr=new SchemeCtr();
		
		final ArrayList<String> info=new ArrayList<String>();
		
		final JComboBox sensorityPerceptionBox = new JComboBox();
		sensorityPerceptionBox.setModel(new DefaultComboBoxModel(new String[] {"1.Completely Limited", "2.Very Limited", "3.Slightly Limited ", "4.No Impairment"}));
		sensorityPerceptionBox.setBounds(457, 77, 143, 20);
		contentPane.add(sensorityPerceptionBox);
		
		Box horizontalBox = Box.createHorizontalBox();
		horizontalBox.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Sensory Perception", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
		horizontalBox.setBounds(10, 59, 590, 55);
		contentPane.add(horizontalBox);
		
		JLabel lblSensoryPereption = new JLabel("             \r\n                     Abillity to respond \r\nmeaninfully to\r\npressure-related discomfort.\r\n\r\n");
		horizontalBox.add(lblSensoryPereption);
		lblSensoryPereption.setFont(new Font("Tahoma", Font.PLAIN, 11));
		
		final JComboBox moistureBox = new JComboBox();
		moistureBox.setModel(new DefaultComboBoxModel(new String[] {"1.Constantly Moist", "2.Often Moist", "3.Occasionally Moist", "4.Rarely Moist"}));
		moistureBox.setBounds(457, 143, 143, 20);
		contentPane.add(moistureBox);
		
		Box horizontalBox_1 = Box.createHorizontalBox();
		horizontalBox_1.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Moisture", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
		horizontalBox_1.setBounds(10, 125, 590, 49);
		contentPane.add(horizontalBox_1);
		
		JLabel lblDegreeToWhich = new JLabel("\r\nDegree to which skin is exposed to moisture.\r\n\r\n");
		lblDegreeToWhich.setFont(new Font("Tahoma", Font.PLAIN, 11));
		lblDegreeToWhich.setBounds(187, 133, 299, 41);
		contentPane.add(lblDegreeToWhich);
		
		Box horizontalBox_2 = Box.createHorizontalBox();
		horizontalBox_2.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Activity", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
		horizontalBox_2.setBounds(10, 182, 590, 52);
		contentPane.add(horizontalBox_2);
		
		JLabel lblDegreeOfPhysical = new JLabel("\r\n\r\nDegree of physical activity.");
		lblDegreeOfPhysical.setFont(new Font("Tahoma", Font.PLAIN, 11));
		lblDegreeOfPhysical.setBounds(187, 193, 299, 41);
		contentPane.add(lblDegreeOfPhysical);
		
		final JComboBox activity = new JComboBox();
		activity.setModel(new DefaultComboBoxModel(new String[] {"1.Bedfast", "2.Chairfast", "3.Walks Occasionally", "4.Walks Frequently"}));
		activity.setBounds(457, 203, 143, 20);
		contentPane.add(activity);
		
		JLabel lblAbilityToChange = new JLabel("\r\nAbility to change and control body position.\r\n");
		lblAbilityToChange.setFont(new Font("Tahoma", Font.PLAIN, 11));
		lblAbilityToChange.setBounds(187, 256, 299, 41);
		contentPane.add(lblAbilityToChange);
		
		Box horizontalBox_3 = Box.createHorizontalBox();
		horizontalBox_3.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Mobility ", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
		horizontalBox_3.setBounds(10, 245, 590, 53);
		contentPane.add(horizontalBox_3);
		
		final JComboBox mobilityBox = new JComboBox();
		mobilityBox.setModel(new DefaultComboBoxModel(new String[] {"1.Competely Immobile", "2.Very Limited ", "3.Slightly Limited", "4.No Limitations"}));
		mobilityBox.setBounds(457, 266, 143, 20);
		contentPane.add(mobilityBox);
		
		Box horizontalBox_4 = Box.createHorizontalBox();
		horizontalBox_4.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Nutrition", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
		horizontalBox_4.setBounds(10, 308, 590, 53);
		contentPane.add(horizontalBox_4);
		
		JLabel lblUsualFoodIntake = new JLabel("                                                            Usual food intake pattern.\r\n");
		lblUsualFoodIntake.setFont(new Font("Tahoma", Font.PLAIN, 11));
		horizontalBox_4.add(lblUsualFoodIntake);
		
		nutritionBox = new JComboBox();
		nutritionBox.setModel(new DefaultComboBoxModel(new String[] {"1.Very Poor", "2.Probably Inadequate", "3.Adequate", "4.Excelllent"}));
		nutritionBox.setBounds(457, 330, 143, 20);
		contentPane.add(nutritionBox);
		
		final JComboBox frictionBox = new JComboBox();
		frictionBox.setModel(new DefaultComboBoxModel(new String[] {"1.Problem", "2.Potential Problem\t", "3.No Apparent Problem"}));
		frictionBox.setBounds(457, 389, 143, 20);
		contentPane.add(frictionBox);
		
		Box horizontalBox_5 = Box.createHorizontalBox();
		horizontalBox_5.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Friction and Shear", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
		horizontalBox_5.setBounds(10, 372, 590, 53);
		contentPane.add(horizontalBox_5);
		
		JLabel lblFrictionAndShear = new JLabel("                                                                   Friction and Shear\r\n");
		lblFrictionAndShear.setFont(new Font("Tahoma", Font.PLAIN, 11));
		horizontalBox_5.add(lblFrictionAndShear);
		
		JButton btnCreate = new JButton("Create");
	
		btnCreate.setBounds(248, 436, 89, 23);
		contentPane.add(btnCreate);
		
		JLabel lblNewLabel = new JLabel("Please name the braden scale:");
		lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 11));
		lblNewLabel.setBounds(147, 21, 211, 14);
		contentPane.add(lblNewLabel);
		
		nameField = new JTextField();
		nameField.setBounds(299, 18, 123, 30);
		contentPane.add(nameField);
		nameField.setColumns(10);
		
		setVisible(true);
		
		btnCreate.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try{
				schemeCtr.createBardenScale(nameField.getText(), sensorityPerceptionBox.getSelectedIndex()+1, moistureBox.getSelectedIndex()+1,activity.getSelectedIndex()+1, mobilityBox.getSelectedIndex()+1, nutritionBox.getSelectedIndex()+1, frictionBox.getSelectedIndex()+1);
				mainFrameLabel.setForeground(new Color(0, 128, 0));
				mainFrameLabel.setText("Status: Scale Succesfully Created!");
				
				info.add(nameField.getText());
				info.add(Integer.toString(sensorityPerceptionBox.getSelectedIndex()+1));
				info.add(Integer.toString(moistureBox.getSelectedIndex()+1));
				info.add(Integer.toString(activity.getSelectedIndex()+1));
				info.add(Integer.toString(mobilityBox.getSelectedIndex()+1));
				info.add(Integer.toString( nutritionBox.getSelectedIndex()+1));
				info.add((Integer.toString(frictionBox.getSelectedIndex()+1)));
				
				model.addRow(info.toArray());
				model.fireTableDataChanged();
			
				
				dispose();
				}
				
				catch(Exception ex)
				{
					System.out.println("Error while creating scale");
				}
			}
		});
	}
}